/**
 * 考试信息管理初始化
 */
var ExamineeScore = {
    id: "ExamineeScoreTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};
var id1 ;
/**
 * 初始化表格的列
 */
ExamineeScore.initColumn = function () {
    return [
            {title: '主键ID', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '准考证号', field: 'examCardNumber', visible: true, align: 'center', valign: 'middle'},
            {title: '考生姓名', field: 'studentName', visible: true, align: 'center', valign: 'middle'},
            {title: '所属学校', field: 'senoirSchoolName', visible: true, align: 'center', valign: 'middle'},
            {title: '语文', field: 'chinese', visible: true, align: 'center', valign: 'middle'},
            {title: '数学', field: 'math', visible: true, align: 'center', valign: 'middle'},
            {title: '英语', field: 'english', visible: true, align: 'center', valign: 'middle'},
            // {title: '加分类型', field: 'scorePlusName', visible: true, align: 'center', valign: 'middle'},
            // {title: '加分分数', field: 'scorePlus', visible: true, align: 'center', valign: 'middle'},
            {title: '中考总成绩', field: 'senoirTotalScore', visible: true, align: 'center', valign: 'middle'} 
    ];
};

/**
 * 检查是否选中
 */
ExamineeScore.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
    	ExamineeScore.seItem = selected[0];
    	id1 = selected[0].id ;
        return true;
    }
};

/**
 * 点击添加考试成績信息
 */
ExamineeScore.openAddExaminee = function () {
    var index = layer.open({
        type: 2,
        title: '添加中考成绩信息',
        area: ['60%', '60%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/inputMidScore/examineeScore_add'
    });
    this.layerIndex = index;
};
/**
 * 打开查看考试成績信息详情
 */
ExamineeScore.openChangeExaminee = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '中考信息详情',
            area: ['60%', '60%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content:Feng.ctxPath + '/inputMidScore/edit?id=' + this.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除考试成績信息
 */
ExamineeScore.delScore = function () {
    if (this.check()) {
    	
    	Feng.confirm("是否删除考生" + ExamineeScore.seItem.studentName + "的中考成绩？",function(){
	        var ajax = new $ax(Feng.ctxPath + "/inputMidScore/remove", function (data) {
	            Feng.success("删除成功!");
	            ExamineeScore.table.refresh();
	        }, function (data) {
	            Feng.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("examineeScoreId",ExamineeScore.seItem.id);
	        ajax.set("examCardNumber",ExamineeScore.seItem.examCardNumber);
	        ajax.start();
    	 });
    		
    }
    
    /**
     *  if (this.check()) {
    	var operation ;
    	Feng.confirm("是否删除考生" + ExamineeScore.seItem.studentName + "？",operation);
    	
    	 operation = function(){
	        var ajax = new $ax(Feng.ctxPath + "/inputMidScore/remove", function (data) {
	            Feng.success("删除成功!");
	            ExamineeScore.table.refresh();
	        }, function (data) {
	            Feng.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("examineeScoreId",ExamineeScore.seItem.id);
	        ajax.start();
    	 };
    	
    }
     */
};

/**
 * 考生模板下载
 */
ExamineeScore.templateDown = function () {
	var operation = function(){
		location.href=Feng.ctxPath + "/static/file/中考成绩导入模板.xlsx";
	 };
	 Feng.confirm("确定下载中考成绩导入模板？",operation);
};

/**
 * 中考成績导入
 */

ExamineeScore.importMidScore = function () {
	 //定义上传文件对象
    var webUploaderObj = new $WebUpload("importMidScore");
    //设置允许上传的文件类型（在web-upload-object中定义了类型）
    webUploaderObj.setAcceptFileType("excel");
    //设置文件上传地址
    webUploaderObj.setUploadUrl(Feng.ctxPath + "/inputMidScore/import");
    //获取webUploader对象，调用create方法，手动绑定事件
    var webUploader = webUploaderObj.create();
    //绑定事件
    webUploader.on('uploadSuccess', function (file, response) {
        Feng.infoDetail("导入结果", response.message.split("\n"), '500px', '500px');
        ExamineeScore.table.refresh();
    });
    // 文件上传失败，显示上传出错。
    webUploader.on('uploadError', function (file, response) {
        Feng.error("上传失败");
    });
};

ExamineeScore.resetSearch = function () {
    $("#examCardNumber").val("");
    $("#studentName").val("");
    $("#senoirSchoolName").val("");
    ExamineeScore.search();
}

/**
 * 查询中考成绩信息列表
 */
ExamineeScore.search = function () {
    var queryData = {};

    queryData['examCardNumber'] = $("#examCardNumber").val();
    queryData['studentName'] = $("#studentName").val();
    queryData['senoirSchoolName'] = $("#senoirSchoolName").val() ;
    ExamineeScore.table.refresh({query: queryData});
};

$(function () {
    var defaultColumns = ExamineeScore.initColumn();
    var table = new BSTable(ExamineeScore.id, "/inputMidScore/list", defaultColumns);
    ExamineeScore.table = table.init();
    ExamineeScore.importMidScore();
});
